<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'

// 1. 定义 ref 设置为 null
const hRef = ref(null)

onMounted(() => {
  console.log(hRef.value)
  // 3.通过 as 进行类型断言
  const h1 = hRef.value! as HTMLHeadingElement
  // 类型 可以通过 document.querySelector 传入具体的标签名来获取
  // document.querySelector('h1')

  // h1.innerHTML = '123'
})
</script>

<template>
  <!-- 2. 和具体的 dom 元素关联起来 -->
  <h1 ref="hRef">我是一个标题哦~</h1>
</template>

<style>
* {
  margin: 0;
  padding: 0;
  list-style: none;
}

.news {
  display: flex;
  height: 120px;
  width: 600px;
  margin: 0 auto;
  padding: 20px 0;
  cursor: pointer;
}

.news .left {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-right: 10px;
}

.news .left .title {
  font-size: 20px;
}

.news .left .info {
  color: #999999;
}

.news .left .info span {
  margin-right: 20px;
}

.news .right {
  width: 160px;
  height: 120px;
}

.news .right img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>